package multi_thread;

/**
 * 死锁代码
 */

public class DeadLock {
    public static Object o1 = new Object();
    public static Object o2 = new Object();

    public static void main(String[] args) {
        Thread a = new Thread(()->{
            while (true){
                synchronized (o1){
                    System.out.println(Thread.currentThread().getName()+" lock o1");
                    synchronized (o2){
                        System.out.println(Thread.currentThread().getName()+" lock o2");
                    }
                }
            }
        },"Thread1");

        Thread b= new Thread(()->{
            while (true){
                synchronized (o2){
                    System.out.println(Thread.currentThread().getName()+" lock o2");
                    synchronized (o1){
                        System.out.println(Thread.currentThread().getName()+" lock o1");
                    }
                }
            }
        },"Thread2");

        a.start();
        b.start();
    }


}
